home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FIX_DESK / SOURCE / PROCESS.C < prev    next >
C/C++ Source or Header  |  1988-09-07  |  5KB  |  214 lines

  1. #include <MacTypes.h>
  2. #include <ResourceMgr.h>
  3. #include <QuickDraw.h>
  4. #include <WindowMgr.h>
  5. #include <ControlMgr.h>
  6. #include <DialogMgr.h>
  7. #include <FileMgr.h>
  8.  
  9. #include "setjmp.h"
  10. #include "fix.h"
  11.  
  12. enum {
  13.     ITEM_PROCESS_STEP = 2,
  14.  
  15.     ITEM_STATS_OK = 1,
  16.     ITEM_STATS_INFO = 3
  17. };
  18.  
  19. static Handle process_item;
  20. static jmp_buf abort;        /* Environment for setjmp(). */
  21. static int desktop_refnum;
  22.  
  23. void show_statistics(void);
  24. void general_init(void);
  25. void general_finish(void);
  26. void general_cleanup(void);
  27.  
  28.     /* Processing control routines. */
  29.  
  30.     /* Handle processing of one volume. */
  31.  
  32. void one_pass()
  33. {
  34.     register DialogPtr process_dialog;
  35.     register int reason;
  36.  
  37.     CouldDialog(DIALOG_PROCESS);
  38.     CouldDialog(DIALOG_STATS);
  39.     CouldAlert(ALERT_GENERAL);
  40.     if (select_volume_dialog(&volume_refnum, &is_hfs)) {
  41.         set_watch_cursor();
  42.         process_dialog = NIL;
  43.         reason = setjmp(abort);
  44.         if (!reason) {                /* Abort to here... */
  45.             general_init();
  46.  
  47.             process_dialog = GetNewDialog(DIALOG_PROCESS, NIL, MINUS_ONE);
  48.             process_item = get_item(process_dialog, ITEM_PROCESS_STEP);
  49.             DrawDialog(process_dialog);
  50.  
  51.                 /* Pre-process the volume. */
  52.  
  53.             GetIndString(string, STR_ID, STR_READDESKTOP);
  54.             SetIText(process_item, string);
  55.  
  56.             if (process_comments)
  57.                 pre_comment_processing();
  58.             if (process_bundles)
  59.                 pre_bundle_processing();
  60.             if (process_appls)
  61.                 pre_appl_processing();
  62.  
  63.                 /* Process the files on the volume. */
  64.  
  65.             GetIndString(string, STR_ID, STR_READDISK);
  66.             SetIText(process_item, string);
  67.             if (is_hfs)
  68.                 hfs_scan_disk();
  69.             else
  70.                 mfs_scan_disk();
  71.  
  72.                 /* Post-process the volume. */
  73.  
  74.             GetIndString(string, STR_ID, STR_UPDATEDESKTOP);
  75.             SetIText(process_item, string);
  76.  
  77.             if (process_comments)
  78.                 post_comment_processing();
  79.             if (process_bundles)
  80.                 post_bundle_processing();
  81.             if (process_appls)
  82.                 post_appl_processing();
  83.  
  84.             general_finish();
  85.             SystemTask();
  86.             DisposDialog(process_dialog);
  87.             set_normal_cursor();
  88.             show_statistics();
  89.         }
  90.         else {    /* Aborted somewhere... */
  91.             if (process_dialog)
  92.                 DisposDialog(process_dialog);
  93.             if (reason > 0)
  94.                 general_cleanup();    /* Try to clean up... */
  95.             set_normal_cursor();
  96.         }
  97.     }
  98.     FreeDialog(DIALOG_PROCESS);
  99.     FreeDialog(DIALOG_STATS);
  100.     FreeAlert(ALERT_GENERAL);
  101. }
  102.  
  103.     /* Do general initialization (open DeskTop file). */
  104.  
  105. static void general_init()
  106. {
  107.     register Handle thing;
  108.  
  109.     GetIndString(string, STR_ID, STR_DESKTOP);
  110.     desktop_refnum = OpenRFPerm(string, volume_refnum, fsRdWrPerm);
  111.     if (desktop_refnum <= 0) {
  112.         GetIndString(string, STR_ID, STR_NODESK);
  113.         ParamText(string, NIL, NIL, NIL);
  114.         set_normal_cursor();
  115.         Alert(ALERT_GENERAL, NIL);
  116.         longjmp(abort, -1);        /* Desktop is not open... */
  117.     }
  118.     else {
  119.         thing = GetResource('STR ', 0);
  120.         HLock(thing);
  121.         GetIndString(string, STR_ID, STR_FINDERID);
  122.         if (!equalstr((StringPtr) *thing, string)) {
  123.             HUnlock(thing);
  124.             ReleaseResource(thing);
  125.             GetIndString(string, STR_ID, STR_BADFINDERID);
  126.             ParamText(string, NIL, NIL, NIL);
  127.             set_normal_cursor();
  128.             Alert(ALERT_GENERAL, NIL);
  129.             longjmp(abort, 1);
  130.         }
  131.         else {
  132.             HUnlock(thing);
  133.             ReleaseResource(thing);
  134.         }
  135.     }
  136. }
  137.  
  138.     /* Finish volume processing. */
  139.  
  140. static void general_finish()
  141. {
  142.     CloseResFile(desktop_refnum);
  143. }
  144.  
  145.     /* Clean up after an abort (if desktop was open). */
  146.  
  147. static void general_cleanup()
  148. {
  149.     SetResFileAttrs(desktop_refnum, mapReadOnly);
  150.     CloseResFile(desktop_refnum);
  151. }
  152.  
  153.     /* Display volume processing statistics. */
  154.  
  155. static void show_statistics()
  156. {
  157.     static unsigned char cr[2] = "\p\r";
  158.  
  159.     register DialogPtr stats_dialog;
  160.     register unsigned char *t;
  161.     int blob;
  162.     unsigned char temp[256], buf[16];
  163.  
  164.     stats_dialog = GetNewDialog(DIALOG_STATS, NIL, MINUS_ONE);
  165.     t = temp;
  166.  
  167.     t[0] = '\0';
  168.     if (process_comments) {
  169.         NumToString(comment_count, buf);
  170.         concatstr(t, buf, t);
  171.         GetIndString(string, STR_ID, (comment_count == 1) ?
  172.                                 STR_COMMENT : STR_COMMENTS);
  173.         concatstr(t, string, t);
  174.         concatstr(t, cr, t);
  175.     }
  176.     if (process_bundles) {
  177.         NumToString(bndl_count,buf);
  178.         concatstr(t, buf, t);
  179.         GetIndString(string, STR_ID, (bndl_count == 1) ?
  180.                                 STR_BUNDLE : STR_BUNDLES);
  181.         concatstr(t, string, t);
  182.         concatstr(t, cr, t);
  183.     }
  184.     if (process_appls && is_hfs) {
  185.         NumToString(appl_count,buf);
  186.         concatstr(t, buf, t); 
  187.         GetIndString(string, STR_ID, (appl_count == 1) ?
  188.                                 STR_APPL : STR_APPLS);
  189.         concatstr(t, string, t);
  190.     }
  191.     SetIText(get_item(stats_dialog, ITEM_STATS_INFO), t);
  192.     ShowWindow(stats_dialog);
  193.     ModalDialog(NIL, &blob);
  194.     DisposDialog(stats_dialog);
  195. }
  196.  
  197.     /* Display directory being processed. */
  198.  
  199. void set_processing(name)
  200.     unsigned char *name;
  201. {
  202.     register unsigned char *s;
  203.  
  204.     s = string;
  205.  
  206.     if (name == NIL)
  207.         GetIndString(s, STR_ID, STR_READDISK);
  208.     else {
  209.         GetIndString(s, STR_ID, STR_READFOLDER);
  210.         concatstr(s, name, s);
  211.     }
  212.     SetIText(process_item, s);
  213. }
  214.